package com.xscr.api.utils;
public class StringUtils extends org.apache.commons.lang.StringUtils{
	
	private static int replace_pre_index = 3;
	
	private static int replace_idcard_pre_index = 4;
	private static int not_replace_idcard_sub_index = 4;
	
	private static String replace_char = "*";
	
	public static String lowerFirstChar(String str){
		if(isEmpty(str)){
			return str;
		}else{
			return String.valueOf(str.charAt(0)).toLowerCase()+str.substring(1);
		}
	}
	
	public static String formateMobile(String mobile){
		String replace = "*****";
		return mobile.substring(0, replace_pre_index)+replace+mobile.substring(replace_pre_index+replace.length());
	}
	
	public static String formateIDCard(String idCard){
		int length = idCard.length();
		int subStringIndex = length - not_replace_idcard_sub_index;
		String pre = idCard.substring(0, replace_idcard_pre_index);
		String preplace = generateReplaceSequence(subStringIndex - replace_idcard_pre_index);
		String sub = idCard.substring(subStringIndex);
		return pre + preplace + sub;
	}
	
	public static void main(String[] args) {
//		System.out.println(formateMobile("18310817558"));
		String idCard = "4101821988108afad8";
		String rut = formateIDCard(idCard);
		System.out.println(rut);
		System.out.println(idCard.length() == rut.length());
	}
	
	public static String generateReplaceSequence(int length){
		StringBuilder builder = new StringBuilder(replace_char);
		while(--length>0){
			builder.append(replace_char);
		}
		return builder.toString();
		
	}
	
}